<?php
/*name:单位管理员控制器
 *time:2017/4/12
 * 王加明
 * */
namespace app\hongyanche\controller;
class  Network{
    //创建新单位
    function  create(){
        $labels = input('labels');
        $res  = model('unit')->create($labels);
        return json($res);
    }
    //查看单位列表
    function getlist(){
        $filter = [
            'page'           =>input('page'),
            'maxPerPage'    =>input('maxPerPage'),
            'keywords'      =>input('keywords'),
            'unit_state'    =>input('unit_state'),
        ];
        $res = model('Unit')->getlist($filter);
        return json($res);
    }
    //管理员审核用户
    function apply_handle(){
        $unit_id=input('unit_id');
        $authorize=input('authorize');
        $reason=input('reason');
        if($reason){
            $reason = $reason;
        }else{
            $reason = null;
        }
        $res = model('Unit')->apply_handle($unit_id,$authorize,$reason);
        return json($res);
    }
    //单位绑定code
    function invite(){
        $unit_id = input('unit_id');
        $email = input('email');
        $res = model('Unit')->invite($unit_id,$email);
        return json($res);
    }
    //撤销邀请
    function invite_cancel(){
        $unit_id = input('unit_id');
        $cancel = input('cancel');//0撤销，1未撤销
        $res = model('Unit')->invite_cancel($unit_id,$cancel);
        return json($res);
    }
    //单位编辑
    function modify(){
        $key = input('key');
        $content = input('content');
        $unit_id = input('unit_id');
        if($unit_id){//当id不存在时为管理员创建
            $unit_id =$unit_id;
        }else{
            $unit_id = null;
        }
        $res = model('Unit')->modify($unit_id,$key,$content);
        return json($res);
    }
    //删除单位
    function remove(){
        $unit_id = input('unit_id');
        $res = model('Unit')->remove($unit_id);
        return json($res);
    }
    //冻结单位
    function close(){
        $unit_id = input('unit_id');
        $close = input('close');
        $res = model('Unit')->close($unit_id,$close);
        return json($res);
    }
    //单位release,0关闭，1开放
    function release(){
        $unit_id = input('unit_id');
        $release = input('released');
        $res = model('Unit')->release($unit_id,$release);
        return json($res);
    }
}